import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

//持久化配置
const persistConfig = {
  key: "root",
  storage,
};

//引入reducer切片文件
import CitySlice from "./CitySlice";
import UserSlice from "./UserSlice";
import TickPersonSlice from "./TickPersonSlice";

//combineReducers合并多个reducer
const rootReducers = combineReducers({
  CitySlice,
  UserSlice,
  TickPersonSlice,
});

//持久化reducer
const persistedReducer = persistReducer(persistConfig, rootReducers);

// 创建一个store实例
const store = configureStore({
  // reducer字段用于指定为当前store提供哪些reducer
  reducer: persistedReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: ["persist/PERSIST"],
      },
    }),
});

export let persistor = persistStore(store);

export default store;